package com.miaosha.error;

public class ErrorException extends Exception implements CommonError{

    private CommonError commonError;

    // 直接接受错误
    public ErrorException(CommonError commonError){
        super();
        this.commonError = commonError;
    }

    // 接受自定义errorMessage构造异常
    public ErrorException(CommonError commonError, String errorMessage){
        super();
        this.commonError = commonError;
        commonError.setErrorMessage(errorMessage);
    }

    @Override
    public int getErrorCode() {
        return commonError.getErrorCode();
    }

    @Override
    public String getErrorMessage() {
        return commonError.getErrorMessage();
    }

    @Override
    public CommonError setErrorMessage(String errorMessage) {
        this.commonError.setErrorMessage(errorMessage);
        return this;
    }
}
